package com.qf.personal.service.impl;


import com.qf.common.base.exception.ServiceException;
import com.qf.common.base.result.RespResult;
import com.qf.common.base.result.ResultCode;
import com.qf.personal.entiy.Type;
import com.qf.personal.mapper.TypeMapper;
import com.qf.personal.service.TypeService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TypeMapperInpl implements TypeService {
    @Resource
    private TypeMapper typeMapper;

    @Override
    public RespResult<List<Type>> selectAll() {
        List<Type> list = typeMapper.selectAll();
        if (!ObjectUtils.isEmpty(list)) {
            return RespResult.success(list);
        } else {
            throw new ServiceException(ResultCode.SYS_ERROR);
        }
    }

    @Override
    public RespResult<List<Type>> selectById(Type type) {
        List<Type> list = typeMapper.selectById(type);
        if (!ObjectUtils.isEmpty(list)) {
            return RespResult.success(list);
        } else {
            throw new ServiceException(ResultCode.SYS_ERROR);
        }
    }

    @Override
    public RespResult<List<Type>> searchType(Type type) {
        List<Type> list = typeMapper.searchType(type);
        if (!ObjectUtils.isEmpty(list)) {
            return RespResult.success(list);
        } else {
            throw new ServiceException(ResultCode.SYS_ERROR);
        }
    }
}
